package My.Nhom2.ServiceSearch;

import java.lang.reflect.Field;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class GoogleMapOfflineActivity extends Activity implements
		OnClickListener {

	/** The text view name service. */
	private TextView tv_name;

	/** The text view address service. */
	private TextView tv_addr;

	/** The image map address service. */
	private ImageView imgView;

	/** The item result service. */
	private DataService item;



	/** The button back. */
	private Button bt_back;



	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dettailsearch);

		item = ServiceSearchActivity.node;

		tv_name = (TextView) findViewById(R.id.tv_name);
		tv_addr = (TextView) findViewById(R.id.tv_address);
		imgView = (ImageView) findViewById(R.id.img_map);



		bt_back = (Button) findViewById(R.id.bt_back);
		bt_back.setOnClickListener(this);



		String str_res = FixString(item.getViDo(), item.getKinhDo());
		int resID = getResId(str_res);
		int resID_notfound = getResources().getIdentifier("notfound",
				"drawable", getPackageName());

		tv_name.setText(item.getTenDiaDiem());
		tv_addr.setText(item.getSoNha() + " " + item.getTenDuong() + ", P." + item.getTenPhuong()
				+ ", Q." + item.getTenQuanHuyen() + ", TP." + item.getTenTinhThanh());

		if (resID == -1)
			imgView.setImageResource(resID_notfound);
		else
			imgView.setImageResource(resID);

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.bt_back) {
			Intent intent = new Intent();
			setResult(RESULT_OK, intent);
			finish();
		}
		
	}

	public static String FixString(String input1, String input2) {
		input1 = "a" + input1;
		String output = input1 + "_" + input2;
		output = output.replace(".", "a");
		return output;
	}

	public static int getResId(String variableName) {
		try {
			Class<My.Nhom2.ServiceSearch.R.drawable> res = R.drawable.class;
			Field field = res.getField(variableName);
			int drawableId = field.getInt(null);
			return drawableId;
		} catch (Exception e) {
			Log.e("MyTag", "Failure to get drawable id.", e);
			return -1;
		}

	}

}
